package com.ruoyi.paip.util;

import com.fasterxml.jackson.core.type.TypeReference;
import com.ruoyi.paip.domain.paip.ConditionData;
import com.ruoyi.paip.domain.paip.Response;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPInputStream;

/**
 * 拍拍 请求工具
 *
 * @author 辛凤文
 * @since 1.0
 */
@Slf4j
public class PaipUtils {

    public static final String URL_PAIP = "https://api.m.jd.com/api";
    public static final String METHOD_GET = "GET";
    public static final String METHOD_POST = "POST";
    public static final String FUNCTION_ID_CATCH_CONDITION = "pp.own.channel.biz.index.catAndCondtion";
    public static final String FUNCTION_ID_GET_CONDITION = "pp.own.channel.biz.index.aggCondition";
    public static final String APP_ID_WX = "paipai_wx";

    //@SneakyThrows
    public static String request(String url, String method, Map<String, String> params, Map<String, String> headers, String requestBody) {
        StringBuilder urlBuilder = new StringBuilder(url);
        urlBuilder.append("?");
        params.forEach((k, v) -> urlBuilder.append(k).append('=').append(v).append('&'));
        String urlString = urlBuilder.toString();
        log.debug("Request URL: {}", urlString);
        HttpURLConnection connection = null;
        //响应体
        String body;
        try {
            // 创建 URL 对象
            URL requestUrl = new URL(urlString);
            // 打开连接
            connection = (HttpURLConnection) requestUrl.openConnection();
            connection.setRequestMethod(method);
            headers.forEach(connection::setRequestProperty);
            if (METHOD_POST.equals(method) && requestBody != null) {
                // 设置是否允许输出
                connection.setDoOutput(true);
                // 获取输出流并写入请求体
                try (java.io.OutputStream outputStream = connection.getOutputStream()) {
                    byte[] input = requestBody.getBytes("utf-8");
                    outputStream.write(input, 0, input.length);
                }
            }
            // 获取响应代码
            int responseCode = connection.getResponseCode();
            log.info("Response Code: {}", responseCode);
            // 处理响应体（如果是gzip编码的）
            InputStream inputStream;
            if ("gzip".equals(connection.getContentEncoding())) {
                inputStream = new GZIPInputStream(connection.getInputStream());
            } else {
                inputStream = connection.getInputStream();
            }
            // 读取响应数据
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            StringBuilder bodyBuilder = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                bodyBuilder.append(line);
            }
            body = bodyBuilder.toString();
            // 打印响应体
            log.info("Response Body: {}", body);
            // 关闭连接
            connection.disconnect();
        } catch (IOException e) {
            log.error("发生错误：{}", e.getMessage());
            throw new RuntimeException(e);
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
        return body;
    }


    //测试
    public static void main(String[] args) throws InterruptedException {
        //catchCondition();
        //getCondition();
        //for (int i = 0; i < 20; i++) {
        //    search();
        //    Thread.sleep(800);
        //}
        //promoBatch();
        //tradeOrder();
        //getPromo();
        //confirmOrder();
        //submitOrder();
        getUserCode();
    }

    /**
     * 模拟搜索
     */
    @SneakyThrows
    public static void search() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.own.channel.biz.index.wechat.list");
        params.put("appid", "paipai_wx");
        //params.put("client", "m");
        //params.put("ext", "%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.2%2Fpages%2Findex%2Findex%22%7D");
        //params.put("t", String.valueOf(System.currentTimeMillis())); // 动态生成时间戳
        //params.put("h5st", "20250204181955914%3Beyqh085vk94lle41%3Bd9bf4" +
        //        "%3Btk03af5171db118pMSszKzN4MysxIJ5wZTadRWMmmvcmZSPnxfJM8uZIq3YbcuuxowykXQyXJ3LacrlG8GFSm4c89xBV" +
        //        "%3B9351b3dec33bb8587f38b43bab734b72%3B4.9%3B1738664395914%3Bq3EpJnoeG6lQ3H4R1Wod7LVPyWFjLDIj7SFjLrJp" +
        //        "-jZf9HIg3T0UzelNJrJdJTEjLrJp-jZX1G2SVqmXBKWVJrJdJ31QHyVT5ipjLD7N%3B0b2d707649a63d21f4789a0475220d78");
        //params.put("uuid", "17379793315541488067752");
        //params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");

        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("content-length", "1190");
        //headers.put("x-referer-page", "/pages/index/index");
        //headers.put("xweb_xhr", "1");
        //headers.put("x-rp-client", "mini_2.0.0");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        //headers.put("x-referer-package", "wx4987f0b3b115aae2");
        //headers.put("content-type", "application/x-www-form-urlencoded");
        //headers.put("accept", "*/*");
        //headers.put("sec-fetch-site", "cross-site");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        //headers.put("cookie", "guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1738149940.1738663899.4");

        // 请求体
        String requestBody = "body=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A12%2C%22source%22%3A1%2C%22conditionJson%22%3A%5B%7B%22cType%22%3A%22range%22%2C%22fromValue%22%3A%22%22%2C%22toValue%22%3A4600%2C%22code%22%3A%22PRICE%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22QUALITY%22%2C%22value%22%3A%2299%22%2C%22name%22%3A%2299%E6%96%B0%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22VERSION%22%2C%22value%22%3A%2216_169_%E5%9B%BD%E8%A1%8C%22%2C%22name%22%3A%22%E5%9B%BD%E8%A1%8C%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22NETWORK%22%2C%22value%22%3A%2217_182_%E5%85%A8%E7%BD%91%E9%80%9A%22%2C%22name%22%3A%22%E5%85%A8%E7%BD%91%E9%80%9A%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%22%2C%22code%22%3A%22BRAND%22%2C%22value%22%3A%228557%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%20Mate%2060%20Pro%22%2C%22code%22%3A%22MODEL%22%2C%22value%22%3A%228295%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22children%22%3Anull%2C%22code%22%3A%22PRODUCT_SOURCE%22%2C%22fromName%22%3Anull%2C%22fromValue%22%3Anull%2C%22name%22%3A%22%E4%B8%A5%E9%80%89%22%2C%22toName%22%3Anull%2C%22toValue%22%3Anull%2C%22value%22%3A%22YX%22%7D%5D%2C%22cid3%22%3A13768%7D";
        String bodyJson = "{\"pageNo\":1,\"pageSize\":12,\"source\":1,\"conditionJson\":[{\"cType\":\"range\"," +
                "\"fromValue\":\"\",\"toValue\":4600,\"code\":\"PRICE\"},{\"cType\":\"term\",\"code\":\"QUALITY\",\"value\":\"99\",\"name\":\"99新\"},{\"cType\":\"term\",\"code\":\"VERSION\",\"value\":\"16_169_国行\",\"name\":\"国行\"},{\"cType\":\"term\",\"code\":\"NETWORK\",\"value\":\"17_182_全网通\",\"name\":\"全网通\"},{\"name\":\"华为\",\"code\":\"BRAND\",\"value\":\"8557\",\"cType\":\"term\"},{\"name\":\"华为 Mate 60 Pro\",\"code\":\"MODEL\",\"value\":\"8295\",\"cType\":\"term\"},{\"cType\":\"term\",\"children\":null,\"code\":\"PRODUCT_SOURCE\",\"fromName\":null,\"fromValue\":null,\"name\":\"严选\",\"toName\":null,\"toValue\":null,\"value\":\"YX\"}],\"cid3\":13768}";

        bodyJson = "{\"pageNo\":1,\"pageSize\":12,\"source\":1,\"conditionJson\":[{\"cType\":\"range\",\"fromValue\":\"\",\"toValue\":4850,\"code\":\"PRICE\"},{\"cType\":\"term\",\"code\":\"QUALITY\",\"value\":\"99\",\"name\":\"99新\"},{\"cType\":\"term\",\"code\":\"VERSION\",\"value\":\"16_169_国行\",\"name\":\"国行\"},{\"cType\":\"term\",\"code\":\"NETWORK\",\"value\":\"17_182_全网通\",\"name\":\"全网通\"},{\"name\":\"华为\",\"code\":\"BRAND\",\"value\":\"8557\",\"cType\":\"term\"},{\"name\":\"华为 Mate 60 Pro\",\"code\":\"MODEL\",\"value\":\"8295\",\"cType\":\"term\"},{\"cType\":\"term\",\"children\":null,\"code\":\"PRODUCT_SOURCE\",\"fromName\":null,\"fromValue\":null,\"name\":\"严选\",\"toName\":null,\"toValue\":null,\"value\":\"YX\"}],\"cid3\":13768}";
        requestBody = "body=" + URLEncoder.encode(bodyJson, "UTF-8");
        //code 0成功 1失败

        // 发送请求
        String response = PaipUtils.request(URL_PAIP, METHOD_POST, params, headers, requestBody);
        System.out.println(response);
    }

    /**
     * 获取所有商品分类/机型/条件
     */
    public static Response<ConditionData> catchCondition() {
        Map<String, String> requestParams = new HashMap<>();
        requestParams.put("functionId", FUNCTION_ID_CATCH_CONDITION);
        requestParams.put("appid", APP_ID_WX);
        //requestParams.put("client", "m");
        //requestParams.put("ext", "%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.1%2Fpages%2Findex%2Findex%22%7D");
        //requestParams.put("t", "1736238045618");
        //requestParams.put("h5st", "20250107162045619%3Byyqe8vlh1ezzuee2%3Bd9bf4%3Btk03ac7df1c3f18pMyszKzMrMTVLesls4UHwq6i74xMlReQ2xz9b2XsPj4YE6KDsbATOXOvJ7wAW0BZ_bEQiu0Jj88Yt%3Bc58b258c19af1e6f2e1a50f69e7d3e28%3B4.9%3B1736238045619%3Bq3EpJjYSGWENxWVfD6FOzXVPyGEjLDIj7SFjLrJp-jZf9HIg3T0UzelNJrJdJTEjLrJp-jJX9CUZb25R4bFbJrJdJ31QHyVT5ipjLD7N%3B49318bef48b5ae775e7c475e12c736b1");
        //requestParams.put("uuid", "17359920210391667687448");
        //requestParams.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");
        //requestParams.put("body", "%7B%22visitChannel%22%3A2%2C%22filterExclusiveStock%22%3Afalse%7D");

        Map<String, String> requestHeaders = new HashMap<>();
        requestHeaders.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/127/page-frame.html");

        String result = request(URL_PAIP, METHOD_GET, requestParams, requestHeaders, null);
        TypeReference<Response<ConditionData>> typeReference =
                new TypeReference<Response<ConditionData>>() {
                };
        return JsonUtils.parse(result, typeReference);
    }

    /**
     * 获取某机型条件选项
     */
    public static void getCondition() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", FUNCTION_ID_GET_CONDITION);
        params.put("appid", APP_ID_WX);
        //params.put("client", "m");
        //params.put("ext", "%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.1%2Fpages%2Findex%2Findex%22%7D");
        //params.put("t", "1737367706474");
        //params.put("uuid", "17373664542942041692207");
        //params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");

        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("content-length", "482");
        //headers.put("x-referer-page", "/pages/index/index");
        //headers.put("xweb_xhr", "1");
        //headers.put("x-rp-client", "mini_2.0.0");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11275");
        //headers.put("x-referer-package", "wx4987f0b3b115aae2");
        //headers.put("content-type", "application/x-www-form-urlencoded");
        //headers.put("accept", "*/*");
        //headers.put("sec-fetch-site", "cross-site");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/127/page-frame.html");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        //headers.put("cookie", "guid=1ec1205933c22eb9b167276658412fac2247da850ef4d411bc16132480d1a753; pt_pin=jd_66b89567df5ab; pt_key=AAJnjhxfADAjuWQqce23ZRdIsoSpCmhdNr8IhvXdHLcsBIgAPJYnRZw5xReJorLyFnlsMd81mHM; pt_token=; __jda=1.17373664542942041692207.1737366454294.1737366454294.1737366455.1");

        // 请求体
        String requestBody = "body=%7B%22filterExclusiveStock%22%3Afalse%2C%22position%22%3A%221%22%2C%22cid3%22" +
                "%3A13768%2C%22conditionJson%22%3A%5B%7B%22name%22%3A%22%E8%8B%B9%E6%9E%9C%22%2C%22code%22%3A%22BRAND%22%2C%22value%22%3A%2214026%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22name%22%3A%22%E8%8B%B9%22%2C%22code%22%3A%22MODEL%22%2C%22value%22%3A%2227692%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22cid3%22%3A13768%2C%22code%22%3A%22CATEGORY%22%2C%22value%22%3A13768%7D%5D%7D";

        // 发送请求
        String response = PaipUtils.request(PaipUtils.URL_PAIP, PaipUtils.METHOD_POST, params, headers, requestBody);
        System.out.println(response);
    }


    /**
     * 批量获取优惠券信息
     */
    @SneakyThrows
    public static void promoBatch() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.own.channel.promo.batch");
        params.put("appid", "paipai_wx");
        //params.put("client", "m");
        //params.put("ext", "%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.1%2Fpages%2Findex%2Findex%22%7D");
        //params.put("t", "1737367706474");
        //params.put("uuid", "17373664542942041692207");
        //params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");

        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("content-length", "482");
        //headers.put("x-referer-page", "/pages/index/index");
        //headers.put("xweb_xhr", "1");
        //headers.put("x-rp-client", "mini_2.0.0");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11275");
        //headers.put("x-referer-package", "wx4987f0b3b115aae2");
        //headers.put("content-type", "application/x-www-form-urlencoded");
        //headers.put("accept", "*/*");
        //headers.put("sec-fetch-site", "cross-site");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/127/page-frame.html");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        //headers.put("cookie", "guid=1ec1205933c22eb9b167276658412fac2247da850ef4d411bc16132480d1a753; pt_pin=jd_66b89567df5ab; pt_key=AAJnjhxfADAjuWQqce23ZRdIsoSpCmhdNr8IhvXdHLcsBIgAPJYnRZw5xReJorLyFnlsMd81mHM; pt_token=; __jda=1.17373664542942041692207.1737366454294.1737366454294.1737366455.1");

        // 请求体
        String requestBody = "body=%7B%22productSet%22%3A%5B%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100865704729635%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100866158250025%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100471211576322%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100786795190283%2C%22type%22%3A1%7D%5D%2C%22source%22%3A1%2C%22channel%22%3A7%7D";
        String bodyJson = "{\"productSet\":[{\"skuId\":10092923798476,\"inspectSkuId\":100865704729635,\"type\":1}," +
                "{\"skuId\":10092923798476,\"inspectSkuId\":100866158250025,\"type\":1},{\"skuId\":10092923798476,\"inspectSkuId\":100471211576322,\"type\":1},{\"skuId\":10092923798476,\"inspectSkuId\":100786795190283,\"type\":1}],\"source\":1,\"channel\":7}";
        requestBody = "body=" + URLEncoder.encode(bodyJson, "UTF-8");
        // 发送请求
        String response = PaipUtils.request(PaipUtils.URL_PAIP, PaipUtils.METHOD_POST, params, headers, requestBody);
        System.out.println(response);
    }

    /**
     * 下单
     */
    @SneakyThrows
    public static void tradeOrder() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.inspect.yp.trade_order.submit");
        params.put("appid", "paipai_direct_h5");
        //&t=1738925098763
        // &client=m
        // &loginType=2
        // &h5st=20250207184458767%3B3xcwrapaaa9p9aa9%3Bb4f9e%3Btk04w4836d91841lMysyKzN4MmVvXRJL4UDLp0GB4UT94Qi824iNZZJZFXbZScJFppFGoc19mtVJdAHINQWNlZGM3UDN%3Bf86f85c01d7c87433a23fcde3c0dac008f342fec43810d9306b67817fc604341%3B5.0%3B1738925098767%3BXRJ6PRHL4UDLp0GB4UT94Qi824iN3Z3L3ZyA3ZXRPp3NoZ3L3hjB2QXR5xZO3FWMnJmBm5GMnFDNmBDAnNWAlJjB0QzBoVGNkBGBmR2M3Z3L3ZyIt8zB08yR5Z3XtRHL28mMzIGBpBWL1YWL4QDB2MTL0AGLnJWN2MWMh52NmRXRfRn94Ay_4MzR5Z3XtRHMrZ2OkBiC0oD-zcEMxQXRfR383ZXRPp3RXUFJ6UyE1EiB3Z3L3lj_1gDBnQXR5xZO3RmNr0jE3Z3L3BT93ZXRPpH65Z3XkZ3L3ZGNkQzR5ZXR5xZOpZ3L35G83QXR5ZXRPpXN5x2RiFyB3ZXR5Z3Xt9GN5x2RjFyB3ZXR5Z3XtZWRfRHMkQzR5ZXR5xZOpZ3L3JG83QXR5ZXRPpXMnZ3L3NG83QXR5ZXRPpXN5x2RnFyB3ZXR5Z3XtRHMrV2OpRXRfRHNkQzR5ZXR5xZOpZ3L3tj83ZXR5Z3XtVGO5x2RmozR5ZXR5xZOpZ3L3pzR5ZXR5xZOpZ3L3Jj83ZXR5Z3XeY3L3Jz_0IS70QXR5xZOcYXRPR3B4E2A182Mk1WL3A2M6Iz-3Z3L3VW93ZXR5Z3XeY3L3ZS93ZXRPp3RlBW75tWMjhD-CYnLphXNoZXELYn9icTAr0jE3Z3L3VD8mQXR5xp7%3Bba8bfffd2187a8d04ef582a964fda6082102a91bd097851eb3e1f420b274edef
        // &uuid=1738925040491252733418
        // &clientVersion=700200
        // &x-api-eid-token=jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU4ABGJ2QAAAAAC3KS6EYEEZFQEUX
        params.put("client", "m");
        //params.put("ext", "%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.2%2Fpages%2Findex%2Findex%22%7D");
        params.put("t", String.valueOf(System.currentTimeMillis())); // 动态生成时间戳
        params.put("loginType", "2"); // 动态生成时间戳
        //params.put("h5st", "20250204181955914%3Beyqh085vk94lle41%3Bd9bf4" +
        //        "%3Btk03af5171db118pMSszKzN4MysxIJ5wZTadRWMmmvcmZSPnxfJM8uZIq3YbcuuxowykXQyXJ3LacrlG8GFSm4c89xBV" +
        //        "%3B9351b3dec33bb8587f38b43bab734b72%3B4.9%3B1738664395914%3Bq3EpJnoeG6lQ3H4R1Wod7LVPyWFjLDIj7SFjLrJp" +
        //        "-jZf9HIg3T0UzelNJrJdJTEjLrJp-jZX1G2SVqmXBKWVJrJdJ31QHyVT5ipjLD7N%3B0b2d707649a63d21f4789a0475220d78");
        params.put("uuid", "1738925040491252733419");
        params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");
        params.put("clientVersion", "700200");
        params.put("x-api-eid-token", "jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5IWIJ7AAAAAACONLTXC2WP3HDMX");
        //jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5IWIJ7AAAAAACONLTXC2WP3HDMX
        //jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5IWIJ7AAAAAACONLTXC2WP3HDMX
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("content-length", "1190");
        //headers.put("x-referer-page", "/pages/index/index");
        //headers.put("xweb_xhr", "1");
        //headers.put("x-rp-client", "mini_2.0.0");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        //headers.put("x-referer-package", "wx4987f0b3b115aae2");
        //headers.put("content-type", "application/x-www-form-urlencoded");
        //headers.put("accept", "*/*");
        //headers.put("sec-fetch-site", "cross-site");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-dest", "empty");
        //headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html");
        headers.put("referer", "https://paipai.m.jd.com/");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        //headers.put("cookie", "guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1738149940.1738663899.4");

        // 请求体
        String requestBody = "body=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A12%2C%22source%22%3A1%2C%22conditionJson%22%3A%5B%7B%22cType%22%3A%22range%22%2C%22fromValue%22%3A%22%22%2C%22toValue%22%3A4600%2C%22code%22%3A%22PRICE%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22QUALITY%22%2C%22value%22%3A%2299%22%2C%22name%22%3A%2299%E6%96%B0%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22VERSION%22%2C%22value%22%3A%2216_169_%E5%9B%BD%E8%A1%8C%22%2C%22name%22%3A%22%E5%9B%BD%E8%A1%8C%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22NETWORK%22%2C%22value%22%3A%2217_182_%E5%85%A8%E7%BD%91%E9%80%9A%22%2C%22name%22%3A%22%E5%85%A8%E7%BD%91%E9%80%9A%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%22%2C%22code%22%3A%22BRAND%22%2C%22value%22%3A%228557%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%20Mate%2060%20Pro%22%2C%22code%22%3A%22MODEL%22%2C%22value%22%3A%228295%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22children%22%3Anull%2C%22code%22%3A%22PRODUCT_SOURCE%22%2C%22fromName%22%3Anull%2C%22fromValue%22%3Anull%2C%22name%22%3A%22%E4%B8%A5%E9%80%89%22%2C%22toName%22%3Anull%2C%22toValue%22%3Anull%2C%22value%22%3A%22YX%22%7D%5D%2C%22cid3%22%3A13768%7D";
        String bodyJson = "{\"orderChannel\":2,\"skuId\":10116185268451,\"inspectSkuId\":101001824057348,\"addrId\":10697899865,\"totalFee\":\"8319.00\",\"shippingFee\":\"0.00\",\"skuFee\":\"8469.00\",\"channelCode\":\"\",\"employeeId\":\"\",\"accountId\":\"\",\"additionalInfo\":{\"client\":\"\",\"unionId\":\"oCwKwuM1ukfsMfL3VidqpxxjV88U\",\"originProduct\":\"\",\"shareExtendInfo\":{\"salerInfo\":\"\",\"shareTime\":\"\"}},\"giftInfo\":{\"gifts\":[{\"id\":\"10129439459245\",\"num\":1},{\"id\":\"10129439459243\",\"num\":1},{\"id\":\"10129439459242\",\"num\":1},{\"id\":\"10129439459241\",\"num\":1},{\"id\":\"10129439459244\",\"num\":1}]},\"couponFee\":-150,\"selectedCouponIds\":[\"124096369536\"]}";
        requestBody = "body=" + URLEncoder.encode(bodyJson, "UTF-8");
        //code 0成功 1失败

        // 发送请求
        String response = PaipUtils.request(URL_PAIP, METHOD_POST, params, headers, requestBody);
        System.out.println(response);
    }

    //POST https://api.m.jd.com/api?functionId=pp.inspect.yp.trade_order.submit&appid=paipai_direct_h5&t=1738925098763&client=m&loginType=2&h5st=20250207184458767%3B3xcwrapaaa9p9aa9%3Bb4f9e%3Btk04w4836d91841lMysyKzN4MmVvXRJL4UDLp0GB4UT94Qi824iNZZJZFXbZScJFppFGoc19mtVJdAHINQWNlZGM3UDN%3Bf86f85c01d7c87433a23fcde3c0dac008f342fec43810d9306b67817fc604341%3B5.0%3B1738925098767%3BXRJ6PRHL4UDLp0GB4UT94Qi824iN3Z3L3ZyA3ZXRPp3NoZ3L3hjB2QXR5xZO3FWMnJmBm5GMnFDNmBDAnNWAlJjB0QzBoVGNkBGBmR2M3Z3L3ZyIt8zB08yR5Z3XtRHL28mMzIGBpBWL1YWL4QDB2MTL0AGLnJWN2MWMh52NmRXRfRn94Ay_4MzR5Z3XtRHMrZ2OkBiC0oD-zcEMxQXRfR383ZXRPp3RXUFJ6UyE1EiB3Z3L3lj_1gDBnQXR5xZO3RmNr0jE3Z3L3BT93ZXRPpH65Z3XkZ3L3ZGNkQzR5ZXR5xZOpZ3L35G83QXR5ZXRPpXN5x2RiFyB3ZXR5Z3Xt9GN5x2RjFyB3ZXR5Z3XtZWRfRHMkQzR5ZXR5xZOpZ3L3JG83QXR5ZXRPpXMnZ3L3NG83QXR5ZXRPpXN5x2RnFyB3ZXR5Z3XtRHMrV2OpRXRfRHNkQzR5ZXR5xZOpZ3L3tj83ZXR5Z3XtVGO5x2RmozR5ZXR5xZOpZ3L3pzR5ZXR5xZOpZ3L3Jj83ZXR5Z3XeY3L3Jz_0IS70QXR5xZOcYXRPR3B4E2A182Mk1WL3A2M6Iz-3Z3L3VW93ZXR5Z3XeY3L3ZS93ZXRPp3RlBW75tWMjhD-CYnLphXNoZXELYn9icTAr0jE3Z3L3VD8mQXR5xp7%3Bba8bfffd2187a8d04ef582a964fda6082102a91bd097851eb3e1f420b274edef&uuid=1738925040491252733418&clientVersion=700200&x-api-eid-token=jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU4ABGJ2QAAAAAC3KS6EYEEZFQEUX HTTP/2
//host: api.m.jd.com
//content-length: 935
//content-type: application/x-www-form-urlencoded
//accept: application/json, text/plain, */*
//x-rp-client: h5_1.0.0
//user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581
//x-referer-page: https://paipai.m.jd.com/inspect/settle
//origin: https://paipai.m.jd.com
//sec-fetch-site: same-site
//sec-fetch-mode: cors
//sec-fetch-dest: empty
//referer: https://paipai.m.jd.com/
//accept-encoding: gzip, deflate, br
//accept-language: zh-CN,zh;q=0.9
//cookie: pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_pin=jd_66b89567df5ab; pwdt_id=jd_66b89567df5ab; pt_st=1_X8tXjH4KwAdtWA4oG7QTUWeeTvYE8M2E4I87zanTLhragiQeT3a9QZYZvezdN2sCaA8DT2C1Gkz0ekPbygCETfHzIFs7t2ynN7x_7-AlDnB2Y5rPI2tolsmizGv2ZvjG2yLLNCwjtBr1u6Bj4AA7FeuI2yJYzSMYVd04ce16Q-zt6NVKQCQZC6a1_9YbYOpaihcZoCaStEZ-odVSi5kfC87YmDnUf_SuTSYg9sfy; __jda=122270672.1738925040491252733418.1738925040.1738925040.1738925040.1; __jdv=122270672%7Cdirect%7C-%7Cnone%7C-%7C1738925040492; __jdc=122270672; 3AB9D23F7A4B3CSS=jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU4ABGJ2QAAAAAC3KS6EYEEZFQEUX; 3AB9D23F7A4B3C9B=MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSI; _gia_d=1; __jdb=122270672.2.1738925040491252733418|1.1738925040; sdtoken=AAbEsBpEIOVjqTAKCQtvQu17lpY-1PCPYIy6C7fXMVP8UzwO533z_ruGJ01b7-n9l5EyPB6XayLqLgyfT-oqutoMvT_YB-q-P2Uw3A2R4s9RAGU61Rb_GaWQTHOJYZo; mba_sid=1.2; mba_muid=1738925040491252733418.1.1738925093030; __jd_ref_cls=Settle_OrderConfirm
//
//body=%7B%22orderChannel%22%3A2%2C%22skuId%22%3A10116185268451%2C%22inspectSkuId%22%3A101001824057348%2C%22addrId%22%3A10697899865%2C%22totalFee%22%3A%228319.00%22%2C%22shippingFee%22%3A%220.00%22%2C%22skuFee%22%3A%228469.00%22%2C%22channelCode%22%3A%22%22%2C%22employeeId%22%3A%22%22%2C%22accountId%22%3A%22%22%2C%22additionalInfo%22%3A%7B%22client%22%3A%22%22%2C%22unionId%22%3A%22oCwKwuM1ukfsMfL3VidqpxxjV88U%22%2C%22originProduct%22%3A%22%22%2C%22shareExtendInfo%22%3A%7B%22salerInfo%22%3A%22%22%2C%22shareTime%22%3A%22%22%7D%7D%2C%22giftInfo%22%3A%7B%22gifts%22%3A%5B%7B%22id%22%3A%2210129439459245%22%2C%22num%22%3A1%7D%2C%7B%22id%22%3A%2210129439459243%22%2C%22num%22%3A1%7D%2C%7B%22id%22%3A%2210129439459242%22%2C%22num%22%3A1%7D%2C%7B%22id%22%3A%2210129439459241%22%2C%22num%22%3A1%7D%2C%7B%22id%22%3A%2210129439459244%22%2C%22num%22%3A1%7D%5D%7D%2C%22couponFee%22%3A-150%2C%22selectedCouponIds%22%3A%5B%22124096369536%22%5D%7D
    @SneakyThrows
    public static void test() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.inspect.yp.trade_order.confirm");
        params.put("appid", "paipai_direct_h5");
        //params.put("t", "1739096268511");
        //params.put("client", "m");
        //params.put("loginType", "2");
        //params.put("h5st", "20250209181748518;dxsd3dcx9waprc21;1fcf8;tk03wd68d1ca618nnQSikubTcptavJ14Brejl3g4YwUYC0JoqRTpBTOjKYmYw_m4Xzy9Kp-_fCq0768wB7VMdbIxD8fc;9ac85722f5d7398d4cebe8ba08bafe9a13df40e67d7f619eeabe90949c697120;5.0;1739096268518;XRJ6PRHNnNz9pUj8g5iB1MWAm4SA3Z3L3ZyA3ZXRPp3NoZ3L3hjB2QXR5xZO3FWMnJmBm5GMnFDNmBDAnNWAlJjB0QzBoVGNkBGBmR2M3Z3L3ZyIt8zB08yR5Z3XtRHL28mMzIGBpBWL1YWL4QDB2MTL0AGLnJWN2MWMh52NmRXRfRn94Ay_4MzR5Z3XtR3MrZ2OkBiC0oD-zcEMxQXRfR383ZXRPp3RY41BqglFiQDG1MmM3Z3L3lj_1gDBnQXR5xZO3RmNr0jE3Z3L3BT93ZXRPpH65Z3XkZ3L3ZGNkQzR5ZXR5xZOpZ3L35G83QXR5ZXRPpXN5x2RiFyB3ZXR5Z3XtNGN5x2RjFyB3ZXR5Z3XtZWRfRHMkQzR5ZXR5xZOpZ3L3JG83QXR5ZXRPpXNnZ3L3NG83QXR5ZXRPpXN5x2RnFyB3ZXR5Z3XtRHMrV2OpRXRfRHNkQzR5ZXR5xZOpZ3L3tj83ZXR5Z3XtVGO5x2RmozR5ZXR5xZOpZ3L3pzR5ZXR5xZOpZ3L3Jj83ZXR5Z3XeY3L3Jz_0IS70QXR5xZOcYXRPR3B4E2A182Mk1WL3A2M6Iz-3Z3L3VW93ZXR5Z3XeY3L3ZS93ZXRPp3RlBW75tWMjhD-CYnLphXNoZXELYn9icTAr0jE3Z3L3VD8mQXR5xp7;2d510c69aaced5c658f85e168a63015b075c3dc381f7a2fe300b69deaf87a14b");
        //params.put("uuid", "1738925040491252733418");
        //params.put("clientVersion", "700200");
        //params.put("x-api-eid-token", "jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5I3LE3QAAAAACE7CHIWWMRD6MAX");
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("accept", "*/*");
        //headers.put("access-control-request-method", "POST");
        //headers.put("access-control-request-headers", "x-referer-page,x-rp-client");
        //headers.put("origin", "https://paipai.m.jd.com");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-site", "same-site");
        //headers.put("sec-fetch-dest", "empty");
        //headers.put("referer", "https://paipai.m.jd.com/");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        // 发送请求（这里是OPTIONS请求，不需要请求体）
        String response = request(URL_PAIP, "OPTIONS", params, headers, null);
        System.out.println(response);
    }

    /**
     * 获取商品优惠
     */
    public static void getPromo() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.own.channel.promo.get");
        params.put("appid", "paipai_wx");
        params.put("client", "m");
        params.put("ext", "{\"referer\":\"wx4987f0b3b115aae2/4.4.2/pages/detail/index\"}");
        params.put("t", "1739096266061");
        params.put("h5st", "20250209181746065;eyqh085vk94lle41;d9bf4;tk03ab5dd1c3e18pMSsxdTYxNEFSRx63OPznwS4sqHCBOZnMR1-Z7VwbLrQobNVyqWfhRHDUkBYfTpRg3Ed7DjL60viC;6eb318e7dca47abb41437733abfb7a6f;4.9;1739096266065;q3EpJnoeG6lQ3H4R1Wod7LVPyWFjLDIj7SFjLrJp-jZf9HIg3T0UzelNJrJdJTEjLrJp-jpapW3fyP1QluFSJrJdJ31QHyVT5ipjLD7N;ade5d5e677f5f516863b00cb3bf7484f");
        params.put("uuid", "17379793315541488067752");
        params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");
        // 这里body参数需要根据实际情况处理，如果是GET请求，不需要处理成URL编码形式放在请求体中，这里只是按照原请求参数结构添加
        params.put("body", "{\"skuId\":\"10101347678146\",\"inspectSkuId\":\"101093433938947\",\"type\":1,\"source\":1,\"channel\":7}");
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        headers.put("host", "api.m.jd.com");
        headers.put("x-referer-page", "/pages/detail/index");
        headers.put("xweb_xhr", "1");
        headers.put("x-rp-client", "mini_2.0.0");
        headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        headers.put("x-referer-package", "wx4987f0b3b115aae2");
        headers.put("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
        headers.put("accept", "*/*");
        headers.put("sec-fetch-site", "cross-site");
        headers.put("sec-fetch-mode", "cors");
        headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html");
        headers.put("accept-encoding", "gzip, deflate, br");
        headers.put("accept-language", "zh-CN,zh;q=0.9");
        headers.put("cookie", "guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1739093434.1739095525.7");
        // 发送请求
        String response = PaipUtils.request(URL_PAIP, METHOD_GET, params, headers, null);
        System.out.println(response);
    }

    /**
     * 确认订单
     */
    public static void confirmOrder() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.inspect.yp.trade_order.confirm");
        params.put("appid", "paipai_direct_h5");
        params.put("t", "1739096268511");
        params.put("client", "m");
        params.put("loginType", "2");
        params.put("h5st", "20250209181748518;dxsd3dcx9waprc21;1fcf8;tk03wd68d1ca618nnQSikubTcptavJ14Brejl3g4YwUYC0JoqRTpBTOjKYmYw_m4Xzy9Kp-_fCq0768wB7VMdbIxD8fc;9ac85722f5d7398d4cebe8ba08bafe9a13df40e67d7f619eeabe90949c697120;5.0;1739096268518;XRJ6PRHNnNz9pUj8g5iB1MWAm4SA3Z3L3ZyA3ZXRPp3NoZ3L3hjB2QXR5xZO3FWMnJmBm5GMnFDNmBDAnNWAlJjB0QzBoVGNkBGBmR2M3Z3L3ZyIt8zB08yR5Z3XtRHL28mMzIGBpBWL1YWL4QDB2MTL0AGLnJWN2MWMh52NmRXRfRn94Ay_4MzR5Z3XtR3MrZ2OkBiC0oD-zcEMxQXRfR383ZXRPp3RY41BqglFiQDG1MmM3Z3L3lj_1gDBnQXR5xZO3RmNr0jE3Z3L3BT93ZXRPpH65Z3XkZ3L3ZGNkQzR5ZXR5xZOpZ3L35G83QXR5ZXRPpXN5x2RiFyB3ZXR5Z3XtNGN5x2RjFyB3ZXR5Z3XtZWRfRHMkQzR5ZXR5xZOpZ3L3JG83QXR5ZXRPpXNnZ3L3NG83QXR5ZXRPpXN5x2RnFyB3ZXR5Z3XtRHMrV2OpRXRfRHNkQzR5ZXR5xZOpZ3L3tj83ZXR5Z3XtVGO5x2RmozR5ZXR5xZOpZ3L3pzR5ZXR5xZOpZ3L3Jj83ZXR5Z3XeY3L3Jz_0IS70QXR5xZOcYXRPR3B4E2A182Mk1WL3A2M6Iz-3Z3L3VW93ZXR5Z3XeY3L3ZS93ZXRPp3RlBW75tWMjhD-CYnLphXNoZXELYn9icTAr0jE3Z3L3VD8mQXR5xp7;2d510c69aaced5c658f85e168a63015b075c3dc381f7a2fe300b69deaf87a14b");
        params.put("uuid", "1738925040491252733418");
        params.put("clientVersion", "700200");
        params.put("x-api-eid-token", "jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5I3LE3QAAAAACE7CHIWWMRD6MAX");
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        headers.put("host", "api.m.jd.com");
        headers.put("content-length", "217");
        headers.put("content-type", "application/x-www-form-urlencoded");
        headers.put("accept", "application/json, text/plain, */*");
        headers.put("x-rp-client", "h5_1.0.0");
        headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        headers.put("x-referer-page", "https://paipai.m.jd.com/inspect/settle");
        headers.put("origin", "https://paipai.m.jd.com");
        headers.put("sec-fetch-site", "same-site");
        headers.put("sec-fetch-mode", "cors");
        headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://paipai.m.jd.com/");
        headers.put("accept-encoding", "gzip, deflate, br");
        headers.put("accept-language", "zh-CN,zh;q=0.9");
        headers.put("cookie", "" +
                "");
        // 构建请求体
        String bodyJson = "{\"orderChannel\":2,\"orderType\":1,\"skuList\":[{\"skuId\":10101347678146," +
                "\"inspectSkuId\":101092765470739}],\"channelCode\":\"\",\"selectedMatchSkus\":[]}";
        String requestBody;
        try {
            requestBody = "body=" + URLEncoder.encode(bodyJson, "UTF-8");
        } catch (Exception e) {
            log.error("请求体编码错误: {}", e.getMessage());
            throw new RuntimeException(e);
        }
        // 发送请求
        String response = request(URL_PAIP, METHOD_POST, params, headers, requestBody);
        System.out.println("确认订单请求响应结果：" + response);
    }

    @SneakyThrows
    public static void submitOrder() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.inspect.yp.trade_order.submit");
        params.put("appid", "paipai_direct_h5");
        //params.put("t", String.valueOf(System.currentTimeMillis()));
        //params.put("client", "m");
        //params.put("loginType", "2");
        // 长文本参数，你可自行复制完整内容
        //params.put("h5st", "很长的 h5st 内容，自行复制");
        //params.put("uuid", "1738925040491252733418");
        //params.put("clientVersion", "700200");
        //params.put("x-api-eid-token", "jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5I3LE3QAAAAACE7CHIWWMRD6MAX");
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        //headers.put("host", "api.m.jd.com");
        //headers.put("content-length", "612");
        //headers.put("content-type", "application/x-www-form-urlencoded");
        //headers.put("accept", "application/json, text/plain, */*");
        //headers.put("x-rp-client", "h5_1.0.0");
        //headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        //headers.put("x-referer-page", "https://paipai.m.jd.com/inspect/settle");
        //headers.put("origin", "https://paipai.m.jd.com");
        //headers.put("sec-fetch-site", "same-site");
        //headers.put("sec-fetch-mode", "cors");
        //headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://paipai.m.jd.com/");
        //headers.put("accept-encoding", "gzip, deflate, br");
        //headers.put("accept-language", "zh-CN,zh;q=0.9");
        // 长文本 cookie，
        //TODO Cookie重要
        headers.put("cookie", "__jdv=122270672%7Cdirect%7C-%7Cnone%7C-%7C1738925040492; __jdc=122270672; 3AB9D23F7A4B3C9B=MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSI; language=zh_CN; cid=5; rurl=%2F%2Fwq.jd.com%2Fpinbind%2Fpintokenredirect%3Ftype%3D1%26biz%3Dhuishou%26rurl%3Dhttps%253A%252F%252Fpaipai.m.jd.com%252Fmine%252Forder%253Ftype%253D1%2526tag%253D-1%2526filter%253D1%252C2%252C6%2526from%253Dxcx_inspectwxapp%26scope%3D0%26sceneid%3D9001%26btnTips%3D%26hideApp%3D0; TrackID=32dINRkuioa51yFjQpXbVTimgrN9tQdzHolAG6VtTLaqIx24RqdR8Sd7HM8l1XHOXXFSSApzO-D2CR4Z5k8m5SZxg6SLQ2BNurETJnzxrstilH23-jikGxI70A5blFSwKAA5DUGTsz9rCxlelytYseOILzOAu7Z0NGfdB59rC6M; buy_uin=300000000023387255; jdpin=jd_66b89567df5ab; mcossmd=b2d7a3fdcc1093943bd06a96c2dc2882; nickname_base64=; open_id=oTGnpnPkJksCTI1VXqO-n5I3ew7I; openid2=E10D0EA46C3D23B90B69AB16E685150E68AAE74682096BD5E27E793714E102D3911BDC5B4A75AF70CB5C75385D39F39E; picture_url=; pinId=e1y1qeVHWacQgTwwYYJpNbV9-x-f3wj7; pinStatus=0; pinsign=069974f34e3fa7b0abe79b95cb474cad; sex=0; wq_skey=za9C4C33C4F33D8853AC816059A78D383D6F9D9609759B48F82A39ED7F7C43FC1BEE8241F28A91F2F2FFB5834E278E5A6EC5CEE20B85F295142FDFFEBF8945B2E34ECE04A2638D62F1C4BE87E1C3BE0EC458036C3DC564A8A19D74932D2CE30FAE; wq_uin=300000000023387255; wq_unionid=oCwKwuM1ukfsMfL3VidqpxxjV88U; wx_nickname=jd_user; country=; sfstoken=tk01wbc531bbea8sMisxKzIrMXgz41v5SVzMc8XPWKYU6XCTd826NoOCQbKwvE5iwnxlV7BSd8sj%2B1TITGLkMFKK3cX4; wq_auth_token=2B5698BE4B61A43BB7021FBBFEDC01DED9B9A33E94A22BA3F6CC31AB22080DD1B83F28FC0FCEF83361F49105C838CD66; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_pin=jd_66b89567df5ab; pwdt_id=jd_66b89567df5ab; __jda=122270672.1738925040491252733418.1738925040.1738925040.1739095574.2; pt_st=1_K6efWWJI7AOqAxYKqunfbxXbas7BsSY6vMphDOLkQh8PdmGpanndmn1i9m3VrXPA69jEt_546ktEB5na7dZ-pzV3rprzMS7r0VfoDY6UbnKCfk5kJpZkHVNZDMB3IQD0BRRm-ttAeB8LAPnVbxWG8NIFle0Hy25T_m6ek55dN-tqzp9LuMnBebZjhVys0bXDw-QKP7N_eEPx4Qv88WAveR_7oIqGGG7njwWp_D4e; 3AB9D23F7A4B3CSS=jdd03MDG3BV6FGBE7VBAGKDTR56ALUM5BAASQPOFN5ANU6FQZGDLOOYRNOM2B4Y5DJHVHQ5EJNZI6WDZBJDJ55ASSCFFOSIAAAAMU5I3LE3QAAAAACE7CHIWWMRD6MAX; _gia_d=1; __jdb=122270672.10.1738925040491252733418|2.1739095574; sdtoken=AAbEsBpEIOVjqTAKCQtvQu17SZWwemEQ7DTu0WyGOrEsYVA6mXAWq_T0jYAiZWoHRSNoNYc2ij2bCtBLcqaTC4VNea9RO9xWI5A2ZAAtd2nnq40htWavb8chjkuUKLyu8yLljSGOGaqN9z6zG_Rh; mba_sid=1.10; mba_muid=1738925040491252733418.1.1739096269041; __jd_ref_cls=Settle_OrderConfirm");
        // 请求体
        String requestBody = "body=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A12%2C%22source%22%3A1%2C%22conditionJson%22%3A%5B%7B%22cType%22%3A%22range%22%2C%22fromValue%22%3A%22%22%2C%22toValue%22%3A4600%2C%22code%22%3A%22PRICE%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22QUALITY%22%2C%22value%22%3A%2299%22%2C%22name%22%3A%2299%E6%96%B0%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22VERSION%22%2C%22value%22%3A%2216_169_%E5%9B%BD%E8%A1%8C%22%2C%22name%22%3A%22%E5%9B%BD%E8%A1%8C%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22NETWORK%22%2C%22value%22%3A%2217_182_%E5%85%A8%E7%BD%91%E9%80%9A%22%2C%22name%22%3A%22%E5%85%A8%E7%BD%91%E9%80%9A%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%22%2C%22code%22%3A%22BRAND%22%2C%22value%22%3A%228557%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%20Mate%2060%20Pro%22%2C%22code%22%3A%22MODEL%22%2C%22value%22%3A%228295%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22children%22%3Anull%2C%22code%22%3A%22PRODUCT_SOURCE%22%2C%22fromName%22%3Anull%2C%22fromValue%22%3Anull%2C%22name%22%3A%22%E4%B8%A5%E9%80%89%22%2C%22toName%22%3Anull%2C%22toValue%22%3Anull%2C%22value%22%3A%22YX%22%7D%5D%2C%22cid3%22%3A13768%7D";
        //String bodyJson = "{\"orderChannel\":2,\"skuId\":10101347678146,\"inspectSkuId\":101092765470739,\"addrId\":10697899865,\"totalFee\":\"2729.00\",\"shippingFee\":\"0.00\",\"skuFee\":\"3149.00\",\"channelCode\":\"\",\"employeeId\":\"\",\"accountId\":\"\",\"additionalInfo\":{\"client\":\"\",\"unionId\":\"oCwKwuM1ukfsMfL3VidqpxxjV88U\",\"originProduct\":\"\",\"shareExtendInfo\":{\"salerInfo\":\"\",\"shareTime\":\"\"}},\"couponFee\":-420,\"selectedCouponIds\":[\"535712092977\"]}";
        //TODO　skuId 为 列表中的youPinSkuId
        //couponFee为优惠券抵扣金额
        //selectedCouponIds为优惠券列表
        String bodyJson = "{\"orderChannel\":2,\"skuId\":10101347678146,\"inspectSkuId\":101093433938947,\"addrId\":10697899865,\"totalFee\":\"2789.00\",\"shippingFee\":\"0.00\",\"skuFee\":\"3209.00\",\"channelCode\":\"\",\"employeeId\":\"\",\"accountId\":\"\",\"additionalInfo\":{\"client\":\"\",\"unionId\":\"oCwKwuM1ukfsMfL3VidqpxxjV88U\",\"originProduct\":\"\",\"shareExtendInfo\":{\"salerInfo\":\"\",\"shareTime\":\"\"}},\"couponFee\":-420,\"selectedCouponIds\":[\"535712092973\"]}";
        requestBody = "body=" + URLEncoder.encode(bodyJson, "UTF-8");
        //code 0成功 1失败
        //requestBody = "body=%7B%22orderChannel%22%3A2%2C%22skuId%22%3A10101347678146%2C%22inspectSkuId%22%3A101092765470739%2C%22addrId%22%3A10697899865%2C%22totalFee%22%3A%222729.00%22%2C%22shippingFee%22%3A%220.00%22%2C%22skuFee%22%3A%223149.00%22%2C%22channelCode%22%3A%22%22%2C%22employeeId%22%3A%22%22%2C%22accountId%22%3A%22%22%2C%22additionalInfo%22%3A%7B%22client%22%3A%22%22%2C%22unionId%22%3A%22oCwKwuM1ukfsMfL3VidqpxxjV88U%22%2C%22originProduct%22%3A%22%22%2C%22shareExtendInfo%22%3A%7B%22salerInfo%22%3A%22%22%2C%22shareTime%22%3A%22%22%7D%7D%2C%22couponFee%22%3A-420%2C%22selectedCouponIds%22%3A%5B%22535712092977%22%5D%7D";

        // 发送请求
        String response = PaipUtils.request(URL_PAIP, METHOD_POST, params, headers, requestBody);
        System.out.println(response);
    }

    /**
     * 获取用户编码
     */
    public static void getUserCode() {
        // 构建请求参数
        Map<String, String> params = new HashMap<>();
        params.put("functionId", "pp.user_wechat.user.code");
        params.put("appid", "paipai_wx");
        params.put("client", "m");
        params.put("ext", "{\"referer\":\"wx4987f0b3b115aae2/4.4.2/pages/detail/index\"}");
        params.put("t", "1739096266454");
        params.put("uuid", "17379793315541488067752");
        params.put("eid", "93A92CCD48893AA941C77D3754ADD7A99A97F22E");
        // 构建请求头
        Map<String, String> headers = new HashMap<>();
        headers.put("host", "api.m.jd.com");
        headers.put("content-length", "87");
        headers.put("x-referer-page", "/pages/detail/index");
        headers.put("xweb_xhr", "1");
        headers.put("x-rp-client", "mini_2.0.0");
        headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581");
        headers.put("x-referer-package", "wx4987f0b3b115aae2");
        headers.put("content-type", "application/x-www-form-urlencoded");
        headers.put("accept", "*/*");
        headers.put("sec-fetch-site", "cross-site");
        headers.put("sec-fetch-mode", "cors");
        headers.put("sec-fetch-dest", "empty");
        headers.put("referer", "https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html");
        headers.put("accept-encoding", "gzip, deflate, br");
        headers.put("accept-language", "zh-CN,zh;q=0.9");
        headers.put("cookie", "guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1739093434.1739095525.7");
        // 构建请求体
        String requestBody = "{\"code\":\"0d3Det000SsgHT1Mg3300hQi8m1Det0K\",\"programType\":16}";
        try {
            requestBody = "body=" + URLEncoder.encode(requestBody, "UTF-8");
        } catch (Exception e) {
            log.error("请求体编码错误: {}", e.getMessage());
            throw new RuntimeException(e);
        }
        // 发送请求
        String response = request(URL_PAIP, METHOD_POST, params, headers, requestBody);
        System.out.println("获取用户码请求响应结果：" + response);
    }

}
/**
 * 优惠券搜索
 */
//POST https://api.m.jd.com/api?functionId=pp.own.channel.promo.batch&appid=paipai_wx&client=m&ext=%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.2%2Fpages%2Findex%2Findex%22%7D&t=1738664396134&h5st=20250204181956135%3Beyqh085vk94lle41%3Bd9bf4%3Btk03af5171db118pMSszKzN4MysxIJ5wZTadRWMmmvcmZSPnxfJM8uZIq3YbcuuxowykXQyXJ3LacrlG8GFSm4c89xBV%3Bb87ed9ac166ce1e42d0ac31efd4db479%3B4.9%3B1738664396135%3Bq3EpJnoeG6lQ3H4R1Wod7LVPyWFjLDIj7SFjLrJp-jZf9HIg3T0UzelNJrJdJTEjLrJp-jpNyeoNmemR46FOJrJdJ31QHyVT5ipjLD7N%3B275b34a67462f4bd008c6a0bdc40dd1d&uuid=17379793315541488067752&eid=93A92CCD48893AA941C77D3754ADD7A99A97F22E HTTP/2
//host: api.m.jd.com
//content-length: 444
//x-referer-page: /pages/index/index
//xweb_xhr: 1
//x-rp-client: mini_2.0.0
//user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/
//    Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581
//x-referer-package: wx4987f0b3b115aae2
//content-type: application/x-www-form-urlencoded
//accept: */*
//sec-fetch-site: cross-site
//sec-fetch-mode: cors
//sec-fetch-dest: empty
//referer: https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html
//accept-encoding: gzip, deflate, br
//accept-language: zh-CN,zh;q=0.9
//cookie: guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1738149940.1738663899.4
//
//body=%7B%22productSet%22%3A%5B%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100865704729635%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100866158250025%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100471211576322%2C%22type%22%3A1%7D%2C%7B%22skuId%22%3A10092923798476%2C%22inspectSkuId%22%3A100786795190283%2C%22type%22%3A1%7D%5D%2C%22source%22%3A1%2C%22channel%22%3A7%7D

/**
 * 搜索
 */
//POST https://api.m.jd.com/api?functionId=pp.own.channel.biz.index.wechat.list&appid=paipai_wx&client=m&ext=%7B%22referer%22%3A%22wx4987f0b3b115aae2%2F4.4.2%2Fpages%2Findex%2Findex%22%7D&t=1738664395913&h5st=20250204181955914%3Beyqh085vk94lle41%3Bd9bf4%3Btk03af5171db118pMSszKzN4MysxIJ5wZTadRWMmmvcmZSPnxfJM8uZIq3YbcuuxowykXQyXJ3LacrlG8GFSm4c89xBV%3B9351b3dec33bb8587f38b43bab734b72%3B4.9%3B1738664395914%3Bq3EpJnoeG6lQ3H4R1Wod7LVPyWFjLDIj7SFjLrJp-jZf9HIg3T0UzelNJrJdJTEjLrJp-jZX1G2SVqmXBKWVJrJdJ31QHyVT5ipjLD7N%3B0b2d707649a63d21f4789a0475220d78&uuid=17379793315541488067752&eid=93A92CCD48893AA941C77D3754ADD7A99A97F22E HTTP/2
//host: api.m.jd.com
//content-length: 1190
//x-referer-page: /pages/index/index
//xweb_xhr: 1
//x-rp-client: mini_2.0.0
//user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11581
//x-referer-package: wx4987f0b3b115aae2
//content-type: application/x-www-form-urlencoded
//accept: */*
//sec-fetch-site: cross-site
//sec-fetch-mode: cors
//sec-fetch-dest: empty
//referer: https://servicewechat.com/wx4987f0b3b115aae2/128/page-frame.html
//accept-encoding: gzip, deflate, br
//accept-language: zh-CN,zh;q=0.9
//cookie: guid=b158ce64da6ebc61bca9c74b0e1a4b07fa052571a7322b1136555ee6dcf16e04; pt_pin=jd_66b89567df5ab; pt_key=AAJnl3XVADCxg_3PUWKm-5sc3vlkEAje4cVDkRwA6rN8KlzQgxMPNCXTSGSBZ3skD4oJRieJkgU; pt_token=; __jda=1.17379793315541488067752.1737979331554.1738149940.1738663899.4
//
//body=%7B%22pageNo%22%3A1%2C%22pageSize%22%3A12%2C%22source%22%3A1%2C%22conditionJson%22%3A%5B%7B%22cType%22%3A%22range%22%2C%22fromValue%22%3A%22%22%2C%22toValue%22%3A4600%2C%22code%22%3A%22PRICE%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22QUALITY%22%2C%22value%22%3A%2299%22%2C%22name%22%3A%2299%E6%96%B0%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22VERSION%22%2C%22value%22%3A%2216_169_%E5%9B%BD%E8%A1%8C%22%2C%22name%22%3A%22%E5%9B%BD%E8%A1%8C%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22code%22%3A%22NETWORK%22%2C%22value%22%3A%2217_182_%E5%85%A8%E7%BD%91%E9%80%9A%22%2C%22name%22%3A%22%E5%85%A8%E7%BD%91%E9%80%9A%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%22%2C%22code%22%3A%22BRAND%22%2C%22value%22%3A%228557%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22name%22%3A%22%E5%8D%8E%E4%B8%BA%20Mate%2060%20Pro%22%2C%22code%22%3A%22MODEL%22%2C%22value%22%3A%228295%22%2C%22cType%22%3A%22term%22%7D%2C%7B%22cType%22%3A%22term%22%2C%22children%22%3Anull%2C%22code%22%3A%22PRODUCT_SOURCE%22%2C%22fromName%22%3Anull%2C%22fromValue%22%3Anull%2C%22name%22%3A%22%E4%B8%A5%E9%80%89%22%2C%22toName%22%3Anull%2C%22toValue%22%3Anull%2C%22value%22%3A%22YX%22%7D%5D%2C%22cid3%22%3A13768%7D
